﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF_Encrypt_Demo
{

    public class XorEncryptHelper
    {
        private static byte encryptionKey = 0xAB;

        // 加密方法
        public static byte[] Encrypt(byte[] data)
        {
            byte[] encryptedData = new byte[data.Length];
            for (int i = 0; i < data.Length; i++)
            {
                encryptedData[i] = (byte)(data[i] ^ encryptionKey); // 使用异或加密
            }
            return encryptedData; // 直接返回加密后的字节数组
        }

        // 解密方法
        public static byte[] Decrypt(byte[] encryptedData)
        {
            byte[] decryptedBytes = new byte[encryptedData.Length];
            for (int i = 0; i < encryptedData.Length; i++)
            {
                decryptedBytes[i] = (byte)(encryptedData[i] ^ encryptionKey); // 使用异或解密
            }
            return decryptedBytes;
        }
    }
}
